<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>登录</title>
    <link href="css/login.css" rel="stylesheet" type="text/css">
    <script type="text/javascript" src="js/jquery-3.1.1.min.js"></script>
    <script >
        function login(){
            var userName = $("[name = 'id']").val();
            if(userName == ""){
                alert("请输入学号");
                return;
            }
            var password = $("[name = 'password']").val();
            if(password == ""){
                alert("请输入密码");
                return;
            }
            var values = $("#login_form").serialize();
            console.log(values);
            var obj = {
                url:"LoginServlet",
                type:"post",
                dataType:"text",
                data:values,
                success:function(data){
                    if(data == 1){
                        //管理员登录
                        alert("管理员登录成功");
                        //跳转到管理员处理页面
                        window.location.href="manager_main.jsp";
                        return;
                    }else if(data == 2){
                        //教师登录
                        alert("教师登录成功");
                        //跳转到教师界面
                        window.location.href="teacher_main.jsp";
                        return;
                    }else if(data == 3){
                        //学生登录
                        alert("学生登录成功");
                        //跳转到学生界面
                        window.location.href="student_main.jsp";
                        return;
                    }
                    //提示用户登录失败
                    alert("账号密码输入错误!");
                }
            }
            $.ajax(obj);

        }
    </script>
</head>

<body class="login">
    <div class="login_logo" style="margin-top:68px;"><p class="text-primary" style="font-family: 华文行楷; font-size: 250%; color: #eff2f3" align="center">我的图书馆</p></div>
    <div class="login_m">
        <div class="login_boder">
            <div class="login_padding">
                <form id="login_form">
                    <h2>用户名</h2>
                    <label>
                        <input type="text" name="id" id="id" class="txt_input">
                    </label>
                    <h2>密码</h2>
                    <label>
                        <input type="password" name="password"  class="txt_input">
                    </label>
                    <div class="rem_sub">
                        <label>
                            <input type="button" class="sub_button" value="登录" style="opacity: 0.7;" onclick="login()">
                        </label>
                    </div>
                </form>
            </div>
        </div><!--login_boder end-->
    </div><!--login_m end-->
    <br />
    <br />
</body>
</html>